﻿@model StudentEditViewModel

@{
    ViewBag.Title = "编辑学生信息";
    var photoPath = $"~/images/noimage.png";
    if (Model.ExistingPhotoPath != null)
    {
        photoPath = $"~/images/avatars/{Model.ExistingPhotoPath}";
    }
}

    <form asp-controller="Home" asp-action="Edit" method="post" class="mt-3" enctype="multipart/form-data">
        <div asp-validation-summary="All" class="text-danger"></div>
        <input hidden="" asp-for="Id"/>
        <input hidden="" asp-for="ExistingPhotoPath"/>
        <div class="form-group row">
            <label asp-for="Name" class="col-sm-2 col-form-label"></label>
            <div class="col-sm-10">
                <input asp-for="Name" class="form-control" placeholder="Name" />
                <span asp-validation-for="Name"></span>
            </div>
        </div>

        <div class="form-group row">
            <label asp-for="Email" class="col-sm-2 col-form-label"></label>
            <div class="col-sm-10">
                <input asp-for="Email" class="form-control" placeholder="Email" />
            </div>
        </div>


        <div class="form-group row">
            <label asp-for="Major" class="col-sm-2 col-form-label"></label>
            <div class="col-sm-10">
                <select asp-for="Major" class="custom-select mr-sm-2" asp-items="Html.GetEnumSelectList(typeof(MajorEnum))">
                    <option value="">请选择</option>
                </select>
                <span asp-validation-for="Major" class="text-danger"></span>

            </div>
        </div>

        <div class="form-group row">
            <label asp-for="Photos" class="col-sm-2 col-form-label"></label>
            <div class="col-sm-10">
                <div class="custom-file">
                    <input asp-for="Photos" multiple class="form-control custom-file-input" />
                    <label class="custom-file-label">点击修改图片</label>
                </div>
            </div>
        </div>
        
        <div class="form-group row col-sm-4 offset-4">
            <img class="img-thumbnail" src="@photoPath" asp-append-version="true"/>
        </div>

        <div class="form-group row">
            <div class="col-sm-10">
                <button type="submit" class="btn btn-primary">更新</button>
                <a asp-controller="Home" asp-action="Index" class="btn btn-primary">取消</a>
            </div>
        </div>


        @section Scripts{
            <script>
            $(document).ready(function() {
                $(".custom-file-input").on("change",
                    function () {

                        var fileLabel = $(this).next(".custom-file-label");
                        var files = $(this)[0].files;
                        if (files.length > 1) {
                            fileLabel.html("你已选择了：" + files.length + " 个文件")
                        } else if (files.length == 1) {
                            fileLabel.html(files[0].name);
                        }

                    });
            });
            </script>
        }

    </form>